/**
 * Created by Administrator on 2016-06-27.
 */
var submit_url = '';
function get_gps(){
    var wt=plus.nativeUI.showWaiting("正在定位...");
    plus.geolocation.getCurrentPosition(geoInf, function(e) {
        plus.nativeUI.toast("获取定位位置信息失败：" + e.message);
    }, {
        geocode: true,
        provider: 'amap'
    });
    wt.close();
}
/**
 * 获取gps
 * @param position
 */
function geoInf(position) {

    var str = "";
    //str += position.addresses + ","; //获取地址信息

    var codns = position.coords; //获取地理坐标信息；
    var lat = codns.latitude; //获取到当前位置的纬度；
    str += lat + ',';
    var longt = codns.longitude; //获取到当前位置的经度
    str += longt;
    mui('#gps_minx')[0].value = str;
    mui('#gps_address')[0].value = str;
}

/**
 * 签到
 */
function sign(){
    var wt = plus.nativeUI.showWaiting("正在打卡，请稍等...");
    var url = '/Manage/Mobile/sign';
    var form = $('#reg_log').serialize();
    $.post(url, form, function(result){
        if(result == 1){
            wt.setTitle("登录成功");
        }else{
            wt.setTitle("登录失败");
        }
        wt.close();
    })
}

function parser_status(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<option value="'+obj.status+'">'+obj.comment+'</option>';
    }
    return str;
}

function parser_weather(){
    var str = '<option>大雨</option><option>中雨</option>' +
    '<option>小雨</option>';
    return str;
}



/***************************     泵站     ***************************/
/**
 * 请求泵站
 */
function request_pump(pump_id, mac_id, gate_id){
    var url = '/Manage/Mobile/get_pumps';
    $.getJSON(url, function(data){
        $('#'+pump_id).append(wirte_pump_pump(data.pump));
        $('#'+mac_id).append(wirte_pump_machines(data.mach))
        $('#'+gate_id).append(wirte_pump_wate(data.we))
    })
}
/**
 * 写入泵站泵机
 * @param $json_objs
 */
function wirte_pump_pump(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="pumpid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>泵站名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>泵机编号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.pump_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>当前状态</label>' +
        '<select class="mui-select" name="status">' +
        '<option selected="selected">请选择</option>' +
        parser_status(obj.statuss) +
        '</select>' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>天气情况</label>' +
        '<select class="mui-select" name="weather">' +
        '<option selected="selected">请选择</option>' +
        parser_weather() +
        '</select>' +
        '</div>';
        str += '</form>';
    }
    return str;
}

function wirte_pump_machines(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="macid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>泵站名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>格栅机编号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.mac_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row ">' +
        '<label>当前状态</label>' +
        '<select class="mui-select" style="border: 1px dotted #D3D3D3;" name="status">' +
        '<option selected="selected">请选择</option>' +
        parser_status(obj.statuss) +
        '</select>' +
        '</div>';
        str += '</form>';
    }
    return str;
}

function wirte_pump_wate(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="eleid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>泵站名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>电表表号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.we_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        ' <label>峰正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="pump_pfa">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>平正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="pump_rta">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>谷正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="pump_lta">' +
        '</div>' +
        ' <div class="mui-input-row">' +
        '<label>正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="pump_fa">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>正向无功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="pump_nfa">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>反向无功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="pump_ra">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>水表读数</label>' +
        '<input type="text" class="mui-input-clear" placeholder="463" name="pump_waterdegrees">' +
        '</div>';
        str += '</form>';
    }
    return str;
}
/***************************     泵站     ***************************/

/***************************     调蓄池     ***************************/
/**
 * 请求调蓄池
 */
function request_csdt(pump_id, mac_id, ele_id, gate_id){
    var url = '/Manage/Mobile/get_csdt';
    $.getJSON(url, function(data){
        $('#'+pump_id).append(wirte_csdt_pump(data.pump));
        $('#'+mac_id).append(wirte_csdt_machines(data.mach))
        $('#'+ele_id).append(wirte_csdt_wate(data.we));
        $('#'+gate_id).append(wirte_csdt_gate(data.gate));

    })
}
/**
 * 写入调蓄池泵机
 * @param $json_objs
 */
function wirte_csdt_pump(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="pumpid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>调蓄池名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>泵机编号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.csdt_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>当前状态</label>' +
        '<select class="mui-select" name="status">' +
        '<option selected="selected">请选择</option>' +
        parser_status(obj.statuss) +
        '</select>' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>天气情况</label>' +
        '<select class="mui-select" name="weather">' +
        '<option selected="selected">请选择</option>' +
        parser_weather() +
        '</select>' +
        '</div>';
        str += '</form>';
    }
    return str;
}

function wirte_csdt_machines(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="macid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>调蓄池名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>格栅机编号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.mac_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row ">' +
        '<label>当前状态</label>' +
        '<select class="mui-select" style="border: 1px dotted #D3D3D3;" name="status">' +
        '<option selected="selected">请选择</option>' +
        parser_status(obj.statuss) +
        '</select>' +
        '</div>';
        str += '</form>';
    }
    return str;
}

function wirte_csdt_wate(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="eleid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>调蓄池名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>电表表号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.we_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        ' <label>峰正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="csdt_pfa">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>平正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="csdt_rta">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>谷正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="csdt_lta">' +
        '</div>' +
        ' <div class="mui-input-row">' +
        '<label>正向有功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="csdt_fa">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>正向无功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="csdt_nfa">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>反向无功</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="csdt_ra">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>水表读数</label>' +
        '<input type="text" class="mui-input-clear" placeholder="463" name="csdt_waterdegrees">' +
        '</div>';
        str += '</form>';
    }
    return str;
}

function wirte_csdt_gate(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="gateid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>调蓄池名称</label>' +
        '<input type="text" placeholder="'+obj.station+'" value="'+obj.station+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>闸门编号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.gate_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row ">' +
        '<label>当前状态</label>' +
        '<select class="mui-select" style="border: 1px dotted #D3D3D3;" name="status">' +
        '<option selected="selected">请选择</option>' +
        parser_status(obj.statuss) +
        '</select>' +
        '<div class="mui-input-row">' +
        '<label>开闸时调蓄池水位（m）</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="gate_startwaterline">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>关闸时调蓄池水位（m）</label>' +
        '<input type="text" class="mui-input-clear" placeholder="009" name="gate_offwaterline">' +
        '</div>' +
        '<div class="mui-input-row" style="height: 130px;">' +
        '<label>开闸原因</label>' +
        '<textarea id="textarea" rows="5" placeholder="请输入开闸原因" name="gate_reson"></textarea>' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>天气情况</label>' +
        '<select class="mui-select" name="weather">' +
        parser_weather() +
        '</select>' +
        '</div>';
        str += '</form>';
    }
    return str;
}
/***************************     调蓄池     ***************************/

/***************************     河道闸门     ***************************/
/**
 * 请求河道闸门
 */
function request_gate( gate_id){
    var url = '/Manage/Mobile/get_river_gates';
    $.getJSON(url, function(data){
        $('#'+gate_id).append(wirte_river_gate(data.gate));

    })
}
/**
 * 写入河道闸门
 * @param $json_objs
 */
function wirte_river_gate(json_objs){
    var str = '';
    for(var i=0;i<json_objs.length;i++){
        var obj = json_objs[i];
        str += '<form class="pupm_form">';
        str += '<input type="hidden" name="model" value="'+obj.model+'"/>';
        str += '<input type="hidden" name="gateid" value="'+obj.id+'"/>';
        str += '<div class="mui-input-row">' +
        '<label>闸门名称</label>' +
        '<input type="text" placeholder="'+obj.gate_name+'" value="'+obj.gate_name+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>泵机编号</label>' +
        '<input type="text" class="mui-input-clear"  value="'+obj.gate_number+'" readonly="true">' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>当前状态</label>' +
        '<select class="mui-select" name="status">' +
        '<option selected="selected">请选择</option>' +
        parser_status(obj.statuss) +
        '</select>' +
        '</div>' +
        '<div class="mui-input-row" style="height: 130px;">' +
        '<label>开闸原因</label>' +
        '<textarea id="textarea" rows="5" placeholder="请输入开闸原因" name="gate_startreason"></textarea>' +
        '</div>' +
        '<div class="mui-input-row">' +
        '<label>天气情况</label>' +
        '<select class="mui-select" name="weather">' +
        '<option selected="selected">请选择</option>' +
        parser_weather() +
        '</select>' +
        '</div>';
        str += '</form>';
    }
    return str;
}
/***************************     河道闸门     ***************************/